package com.saile.controller.admin.messageBoard;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.saile.controller.base.BaseController;
import com.saile.def.Constant;
import com.saile.domain.MessageBoard;
import com.saile.result.ResultObj;
import com.saile.service.AdvertService;
import com.saile.service.MediaService;
import com.saile.service.MessageBoardService;
import com.saile.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

/**
 * Created by lutao on 2017/7/14.
 * 先锋号controller
 */
@RequestMapping("/admin/messageBoard")
@Controller
public class AdminMessageBoardController extends BaseController {
    @Autowired
    AdvertService advertService;
    @Autowired
    NewsService newsService;
    @Autowired
    MediaService mediaService;
    @Autowired
    MessageBoardService messageBoardService;


    /**
     * 红领巾小提案列表
     * @return
     */
    @RequestMapping(value = "/messageBoardList")
    public ModelAndView messageBoardList(Integer page, Integer pageSize) {
        ModelAndView mov = new ModelAndView();
        mov.setViewName("/admin/messageBoard/messageBoardList");


        try {
            if (page == null || page == 0) {
                page = Constant.PAGENUM;
            }
            // 设置每页记录数
            if (pageSize == null || pageSize == 0) {
                pageSize = Constant.PAGESIZENum;
            }
            Map<String,String> map=super.showRequestParameters();
            map.put("page",String.valueOf(page));
            map.put("pageSize",String.valueOf(pageSize));
            PageHelper.startPage(page, pageSize);
            List<MessageBoard> messageBoardList = messageBoardService.getMessageBoardList(map);
            PageInfo<MessageBoard> pageinfo = new PageInfo<MessageBoard>(messageBoardList);
            mov.addObject("pageinfo",pageinfo);
        } catch (Exception e) {

            e.printStackTrace();
        }


        return mov;
    }


    /**
     * 获取红领巾小提案列表
     * @return
     */
    @RequestMapping(value = "/modifyMessageBoardStatus")
    @ResponseBody
    public String modifyMessageBoardStatus(MessageBoard messageBoard) {
        ResultObj resultObj = new ResultObj();
        resultObj.setCode(ResultObj.CODE_SUCCESS);
        try {


            messageBoardService.modifyMessageBoard(messageBoard);

            resultObj.setMsg("操作成功！");
        } catch (Exception e) {
            resultObj.setCode(ResultObj.CODE_FAIL);
            resultObj.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return resultObj.toJson();
    }



}
